/*
 * @Author: xyq
 * @Date: 2021-02-08 15:37:00
 * @LastEditors: xyq
 * @LastEditTime: 2021-03-04 17:24:25
 * @FilePath: \little-eight\src\utils\utils.js
 */
import JSEncrypt from 'jsencrypt/bin/jsencrypt';
function setSession(key, value) {
  let val = JSON.stringify(value);
  return sessionStorage.setItem(key, val);
}
function getSession(key) {
  return JSON.parse(sessionStorage.getItem(key));
}
function removeSession(key) {
  sessionStorage.removeItem(key);
}
const publicKey =
  'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALbGzsSXmWQ+LuVlyCzAEdarqaNt8l0e3f22bYFJi6VAoWD3+Ab/iNrqYkzATQ8ow0w9rlLmVaQ9TLZ8wZUtEm0CAwEAAQ==';

const privateKey =
  'MIIBVgIBADANBgkqhkiG9w0BAQEFAASCAUAwggE8AgEAAkEAtsbOxJeZZD4u5WXILMAR1q' +
  'upo23yXR7d/bZtgUmLpUChYPf4Bv+I2upiTMBNDyjDTD2uUuZVpD1MtnzBlS0SbQIDAQABAkAgXYH9s+6Ynp5FRsm0iupdvhYS94QkU' +
  'zPyGly3uSM+Rq8oPQ2AEgGY7vwRxX2mCRWE1F2nz8p/nJq7wSYjghjtAiEA+ZPKlNmrdtDrdPy0c9cKPixsZmdEET+wvirGEZC9M9sC' +
  'IQC7eu9cqrQDrf66eJRG6Mb50hrFuLubTFNTtIxbmnVJVwIhAJBu5jMEUUV+nHTkde4ACa53ePg+VNcCm99B08SAle43AiEAmACJNxm' +
  'Tz/PvNiJzHba3NG87k5k+SiAs4w3cSpzFgQsCIQDveWuGTPcChfvfLnRO58APlxiFIvGuSMriMYCvlITTZA==';
//加密
function encrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey); // 设置公钥
  return encryptor.encrypt(txt); // 对数据进行加密
}
//解密
function decrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPrivateKey(privateKey); // 设置私钥
  return encryptor.decrypt(txt); // 对数据进行解密
}
export { setSession, getSession, removeSession, encrypt, decrypt };
